<template>
	<view>
		<view class="code-box">
			<view class="list-box" v-for="(item,index) in list" :key="index" @click="listRouter(item)">
				<image class="box-img" :src="item.icon" mode=""></image>
				<view class="box-right">
					<view class="box-title">
						{{item.name}}
					</view>
					<view class="box-title" style="height: 40rpx; line-height: 40rpx;">
						<text>{{item.exercisedCount > 0 ? '已练习' : '未练习'}}</text>
						<text>{{item.exercisedCount}}节</text>
						<text>练习共{{item.courseCount}}节</text>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import {baseUrl} from '../../api/index.js'
	import {booksTree,bookTreesExercise} from '../../api/api.js'
	export default {
		data() {
			return {
				list:[],
				showOptionalCourse:true,
			}
		},
		onShow() {
			this.addRandomData()
		},
		methods: {
			addRandomData() {
				this.list = []
				let id = uni.getStorageSync('userObj') ? uni.getStorageSync('userObj').profession.id : ''
				bookTreesExercise({professionId:id}).then(resp=>{
					resp.forEach(e=>{
						e.icon = baseUrl + e.icon
					})
					this.list = resp
				})
			},
			listRouter(item){
				let itemObj = JSON.stringify(item)
				uni.navigateTo({
					url:`../list/list?item=${itemObj}&professionId=${uni.getStorageSync('userObj').profession.id}&showOptionalCourse=true&lianxi=true`
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.code-box{
	padding: 30rpx;
	.list-box{
		height: 100rpx;
		margin-bottom: 30rpx;
		.box-img{
			width: 100rpx;
			height: 100rpx;
			border-radius: 10rpx;
			float: left;
		}
		.box-right{
			margin-left: 120rpx;
			.box-title{
				height: 60rpx;
				line-height: 60rpx;
				font-size: 36rpx;
				text{
					font-size: 28rpx;
					display: inline-block;
					margin-right: 20rpx;
					color: #000;
					opacity: 0.45;
				}
				text:first-child{
					background-color: #F8F9F9;
					border-radius: 5rpx;
					padding: 0 10rpx;
				}
				text:last-child{
					border-left: #ccc solid 2rpx;
					padding-left: 20rpx;
				}
			}
		}
		:after{
			content: "";
			height: 0;
			line-height: 0;
			display: block;
			visibility: hidden;
			clear: both;
		}
	}
}
</style>
